print('initializing fdtd material grid')

#基于目标计算问题空间的大小
#位置和边界条件
from calculate_domain_size import *

#创建数组存储每个网格的媒质类型索引
#在问题空间，默认空间是被空气填充的通过初始化数组by np.ones??
material_3d_space=np.ones((nx,ny,nz),dtype=np.int32)

#通过对material_3d_space在每个单元格分配媒质类型索引来在问题空间中创建三维对象
#创建长方体
from create_bricks import *
#创建球体
from create_spheres import *
#创建网格模型
from create_structure_mesh import *
# from create_prism import *  # 创建球体
# from create_cylinders import * # 创建圆柱
#由(nx,ny,nz)单元组成问题空间的媒质分量数组
eps_r_x=np.ones((nx,nyp1,nzp1))
eps_r_y=np.ones((nxp1,ny,nzp1))
eps_r_z=np.ones((nxp1,nyp1,nz))
mu_r_x=np.ones((nxp1,ny,nz))
mu_r_y=np.ones((nx,nyp1,nz))
mu_r_z      = np.ones (((nx  , ny   , nzp1)))
sigma_e_x   = np.zeros((nx  , nyp1 , nzp1))
sigma_e_y   = np.zeros((nxp1, ny   , nzp1))
sigma_e_z   = np.zeros((nxp1, nyp1 , nz))
sigma_m_x   = np.zeros((nxp1, ny   , nz))
sigma_m_y   = np.zeros((nx  , nyp1 , nz))
sigma_m_z   = np.zeros((nx  , ny   , nzp1))
deps_x = np.zeros((nx  , nyp1 , nzp1))
deps_y = np.zeros((nxp1, ny   , nzp1))
deps_z = np.zeros((nxp1, nyp1 , nz))
tau_k_x = np.zeros((nx  , nyp1 , nzp1))
tau_k_y = np.zeros((nxp1, ny   , nzp1))
tau_k_z = np.zeros((nxp1, nyp1 , nz))
density = np.ones((nxp1, nyp1 , nzp1))
from environment_pool import brian_pool,mesh_type_pool
 
#print('mesh_type_pool:',mesh_type_pool)
if(mesh_type_pool<=2):
    if(mesh_type_pool==0):
        n3density= brian_pool["n3density"]           
        n3tissueMatrix_deps= brian_pool["n3tissueMatrix_deps"] 
        n3tissueMatrix_eps= brian_pool["n3tissueMatrix_eps"]  
        n3tissueMatrix_sigma= brian_pool["n3tissueMatrix_sigma"]
        n3tissueMatrix_tau_k= brian_pool["n3tissueMatrix_tau_k"]
    else:
        from define_geometry import n3tissueMatrix_eps,n3density,n3tissueMatrix_deps,n3tissueMatrix_sigma,n3tissueMatrix_tau_k
    #TODO:此处定义了TN*和n_*
    TN1 = boundary["air_buffer_number_of_cells_xn"] + boundary["cpml_number_of_cells_xn"]
    n_1,n_2,n_3 = n3tissueMatrix_eps.shape 
    #print(TN1,TN1+n_1,TN1,TN1+n_2,TN1+5,TN1+n_3+5)
    eps_r_x[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_eps #放置的位置等价为空气层在各个方向的设置层
    eps_r_y[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_eps 
    eps_r_z[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_eps 

    deps_x[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_deps #放置的位置等价为空气层在各个方向的设置层
    deps_y[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_deps 
    deps_z[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_deps 

    tau_k_x[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_tau_k #放置的位置等价为空气层在各个方向的设置层
    tau_k_y[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_tau_k 
    tau_k_z[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_tau_k

    sigma_e_x[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_sigma
    sigma_e_y[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_sigma
    sigma_e_z[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3tissueMatrix_sigma
    #print(TN1,TN1+n_1,TN1,TN1+n_2,TN1+5,TN1+n_3+5)
    density[TN1:TN1+n_1,TN1:TN1+n_2,TN1+5:TN1+n_3+5] = n3density
else:
    TN1 = 0
    n_1,n_2,n_3 = n3tissueMatrix_eps.shape
#print(np.sum(np.abs(sigma_e_x)))
#计算媒质分量的平均值
from calculate_material_component_values import *
#print(np.sum(np.abs(sigma_e_x)))
ncells = 8
#创建零厚度的PEC平板
print('creating PEC plates on the material grid')
from get_node_indices import get_node_indices

for ind in np.arange(number_of_bricks):
    mtype     = bricks[ind]["material_type"]
    sigma_pec = material_types[mtype]["sigma_e"]

    # convert coordinates to node indices on the FDTD grid
    ni = get_node_indices(bricks[ind], fdtd_domain)
    is0 = ni["is"]
    js = ni["js"] 
    ks = ni["ks"] 
    ie  = ni["ie"]
    je = ni["je"]
    ke = ni["ke"]
    
    # find the zero thickness bricks
    if (is0 == ie):
        sigma_e_y[is0-1, js-1:je-1, ks-1:ke  ] = sigma_pec
        sigma_e_z[is0-1, js-1:je,   ks-1:ke-1] = sigma_pec
    if (js == je):
        sigma_e_z[is0-1:ie,   js-1, ks-1:ke-1] = sigma_pec
        sigma_e_x[is0-1:ie-1, js-1, ks-1:ke  ] = sigma_pec
    if (ks == ke):
        sigma_e_x[is0-1:ie-1, js-1:je,   ks-1] = sigma_pec
        sigma_e_y[is0-1:ie,   js-1:je-1, ks-1] = sigma_pec
# create_dispersive_objects